package group2assignone.ucm.manager;

import group2assignone.dao.MyDAO;
import group2assignone.model.Flight;
import group2assignone.ucm.UCController;
import group2assignone.ucm.UCStartup;
import group2assignone.view.manager.CreateFlightView;
import group2assignone.view.manager.ManagerView;

/**
 * use case to create a flight
 * @author group2
 */
public class UCCreateFlight implements UCController {

    private CreateFlightView flightView = new CreateFlightView();
    private Flight f = new Flight();

    /**
     * sets view and flight
     * @param fView
     * @param flight
     */
    public UCCreateFlight(CreateFlightView fView, Flight flight) {

        flightView = fView;
        f = flight;
    }

    @Override
    public void run() {
        //When done, save flight to database
        MyDAO coms = UCStartup.getInstance().getDAO();
        coms.sQLCreateFlight(f);
        //Close window and open main login screen
        flightView.dispose();
        ManagerView mv = ManagerView.getInstance();
        mv.setVisible(true);
    }
}
